package com.example.jdktest.controller;

import com.example.jdktest.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: dangwen
 * @createDate: 2020/12/1
 */
@RestController
public class UserController {

    @Autowired
    private HttpServletRequest request;

    @GetMapping("getUser")
    public User getUser() {
        User user = new User();
        return user;
    }

    @PostMapping("toUser")
    public User getUsers() {
        User user = new User();
        String header = request.getHeader("my-header");
        System.out.println(header);
        String name = request.getParameter("name");
        String age = request.getParameter("age");
        return user;
    }

    @GetMapping("toUser")
    public User toUser() {
        User user = new User();
        String header = request.getHeader("my-header");
        System.out.println(header);
        String name = request.getParameter("name");
        String age = request.getParameter("age");
        return user;
    }

    @GetMapping("user")
    public User toUser(HttpServletRequest request) {
        User user = new User();
        String header = request.getHeader("my-header");
        System.out.println(header);
        String name = request.getParameter("name");
        String age = request.getParameter("age");
        return user;
    }

    @GetMapping("/doFilter")
    public String doFilter(){
        return "doFilter_success";
    }

}
